﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint.New
{
    // Advantages: handles constant key renaming.
    // Disadvantages: holds ref to const object which dies if const object is deleted.
    // Needs to be notified if const object is deleted OR this could be handled by
    // some external class.
    public class DynamicConstantSource : ConstantSource
    {
        IConstantsCollection mConstants;
        IConstant mConstant;

        public DynamicConstantSource() // Parameterless constructor required for deserialization.
        {
            Ppt.Presentation pres = Globals.Application.ActivePresentation;
            mConstants = Globals.PresentationConstants[pres].Constants;
        }

        public string StoredName // This property holds the serializable info.
        {
            get { return mConstant.Name; }
            set
            {
                mConstant = mConstants.Lookup(value);
            }
        }

        [XmlIgnore]
        public override IConstant Constant
        {
            get { return mConstant; }
            set { mConstant = value; }
        }

        public override string GetValue()
        {
            return mConstant.Value;
        }
    }
}
